package cn.edu.fzu.homemaking.domain.handler;

import cn.edu.fzu.homemaking.domain.enums.ServerModeEnum;
import cn.edu.fzu.homemaking.domain.enums.ServerModeEnum;
import org.apache.ibatis.type.BaseTypeHandler;
import org.apache.ibatis.type.JdbcType;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * @author yifan
 * @date 2023/4/8
 */
public class ServerModeEnumHandler extends BaseTypeHandler<ServerModeEnum> {
    @Override
    public void setNonNullParameter(PreparedStatement ps, int i, ServerModeEnum parameter, JdbcType jdbcType)
            throws SQLException {
        ps.setInt(i, parameter.getValue());
    }


    @Override
    public ServerModeEnum getNullableResult(ResultSet rs, String columnName) throws SQLException {
        return ServerModeEnum.parse(rs.getInt(columnName));
    }


    @Override
    public ServerModeEnum getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
        return ServerModeEnum.parse(rs.getInt(columnIndex));
    }


    @Override
    public ServerModeEnum getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
        return ServerModeEnum.parse(cs.getInt(columnIndex));
    }
}
